package com.fausto.learnimprint.core.service.impl

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import com.fausto.learnimprint.cache.RedisCache
import com.fausto.learnimprint.cache.RedisKey
import com.fausto.learnimprint.core.mapper.BlogMapper
import com.fausto.learnimprint.core.model.entity.Blog
import com.fausto.learnimprint.core.service.IBlogService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

/**
 *
 *
 * 服务实现类
 *
 *
 * @author fausto
 * @since 2022-03-28
 */
@Service
class BlogServiceImpl : ServiceImpl<BlogMapper, Blog>(), IBlogService {

    @Autowired
    lateinit var blogMapper: BlogMapper

    /**
     *      通过博文ID获取博文
     */
    @RedisCache(key = RedisKey.BLOG_KEY)
    override fun findBlogById(blogId: Int): Blog {
        return blogMapper.selectById(blogId) ?: throw Exception("博文不存在或已被管理员删除")
    }


}